package com.vincent.music.kkmusicapi.api;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.vincent.music.kkmusicapi.http.ApiCallback;
import com.vincent.music.kkmusicapi.http.HttpException;
import com.vincent.music.kkmusicapi.parse.Failed;
import com.vincent.music.kkmusicapi.parse.SearchMusic;
import com.vincent.music.kkmusicapi.parse.WangYiYun;
import com.vincent.music.kkmusicapi.services.ApiService;
import com.vincent.music.kkmusicapi.utils.AppConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.lang.reflect.Type;

@RestController
@RequestMapping(value = "music",produces = "text/plain;charset=UTF-8")
public class MusicApi {

//    @Autowired
//    PrintService printService;
//
//    @Autowired
//    FeignService2 feignService2;
//
//    @Autowired
//    TokenDemoClient tokenDemoClient;

    @ResponseBody
    @RequestMapping(value = "getToken")
    public String token() {
        return "aasdfafdsafsad";
    }

    @ResponseBody
    @RequestMapping(value = "getUser")
    public String getUser() {
        return "已经成功监控了婷的Iphone 11手机，解锁需要人工授权！！！";
    }

    @ResponseBody
    @RequestMapping(value = "baidu")
    public String getUser2() {
        return "<html><a href='http://www.baidu.com'>BaiDu</a></html>";
    }

    @ResponseBody
    @RequestMapping(value = "/getMusicByName")
    public String getMusicByName() {
        return "dddd ddddddd";
    }

    @ResponseBody
    @RequestMapping(value = "/search")
    public ApiCallback search(String keywords) {
        String url = AppConfig.API_MUSIC_URL + String.format("search/get/web?csrf_token=hlpretag=&hlposttag=&s=%s&type=1&offset=0&total=true&limit=2", keywords);
        ApiCallback<WangYiYun<SearchMusic>> wangYiYun = apiService.sendRequest(url);
        if (wangYiYun.getCode() != 200) {
            return wangYiYun;
        }
        return ApiCallback.success(wangYiYun.getData());
    }

//    @PostMapping("/outSide")
//    public String test(@RequestBody Music music) {
//        return printService.print(music);
//    }
//
//    //测试feign调用外部接口入口
//    @PostMapping("/test2")
//    public String test2(@RequestBody Music music) {
//        return feignService2.getMessage(music);
//    }
//
//    @PostMapping("/testToken")
//    public String test4(@RequestBody Music music) {
//        return tokenDemoClient.getMessage(music);
//    }

    private final ApiService apiService;

    public MusicApi(@Autowired ApiService apiService) {
        this.apiService = apiService;
    }


}
